//时间戳转标准时间
export const formatTime = (date1, type) => {
    let date = new Date(date1);
    let year = date.getFullYear()
    let month = date.getMonth() + 1
    let day = date.getDate()

    let hour = date.getHours()
    let minute = date.getMinutes()
    let second = date.getSeconds()

    if (type == 'yyyy-mm-dd') {
        return [year, month, day].map(formatNumber).join('-')
    } else {
        return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
    }
};

function formatNumber(n) {
    n = n.toString()
    return n[1] ? n : '0' + n
};

// 分割文件名
export const splitFileName = (text) => {
    let pattern = /\.{1}[a-z]{1,}$/;
    if (pattern.exec(text) !== null) {
        return (text.slice(0, pattern.exec(text).index));
    } else {
        return text;
    }
};

//获取url后面的参数
export const GetQueryString = (name) => {
    let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    let r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return decodeURI(r[2]);
    }
    return null;
};